package com.xls.box2023.jinbi;


import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.lzz.bottomencapsulation.consts.EventbusCode;
import com.lzz.bottomencapsulation.eventbus.MessageEvent;
import com.xls.box2023.R;
import com.xls.box2023.jinbi.tixian.TiXianActivity;
import com.xls.box2023.jinbi.tixianjilu.TiXianJiLuActivity;
import com.xls.box2023.mvp.MVPBaseActivity;
import com.xls.xrecyclerview.XRecyclerView;


/**
 * MVPPlugin
 */

public class JinBiActivity extends MVPBaseActivity<JinBiContract.View, JinBiPresenter> implements JinBiContract.View, View.OnClickListener {

    private TextView title_text;
    private TextView title_back;
    private RelativeLayout title_rl_content;
    private TextView jinbi_yue_title;
    private TextView jinbi_yue;
    private TextView jinbi_unit;
    private TextView jinbi_tixianjilu;
    private TextView jinbi_tixian;
    private TextView jinbi_list_title;
    private TextView jinbi_jifenduihuanjilu;
    private XRecyclerView jinbi_list;

    public static void startActivity(Activity activity) {
        Intent intent=new Intent(activity,JinBiActivity.class);
        activity.startActivity(intent);
    }

    @Override
    public int getView() {
        return R.layout.activity_jinbi;
    }

    @Override
    public void initView() {

        title_text = findViewById(R.id.title_text);
        title_back = findViewById(R.id.title_back);
        title_rl_content = findViewById(R.id.title_rl_content);
        jinbi_yue_title = findViewById(R.id.jinbi_yue_title);
        jinbi_yue = findViewById(R.id.jinbi_yue);
        jinbi_unit = findViewById(R.id.jinbi_unit);
        jinbi_tixianjilu = findViewById(R.id.jinbi_tixianjilu);
        jinbi_tixian = findViewById(R.id.jinbi_tixian);
        jinbi_list_title = findViewById(R.id.jinbi_list_title);
        jinbi_jifenduihuanjilu = findViewById(R.id.jinbi_jifenduihuanjilu);
        jinbi_list = findViewById(R.id.jinbi_list);

        title_text.setText("我的金币");
        setAdapter();
        title_back.setOnClickListener(this);
        jinbi_tixianjilu.setOnClickListener(this);
        jinbi_jifenduihuanjilu.setOnClickListener(this);
        jinbi_tixian.setOnClickListener(this);
        jinbi_list.setLoadingListener(mPresenter.getLoadingListener());
    }

    /**
     * 设置游戏下载消耗记录  列表适配器
     */
    private void setAdapter() {
        jinbi_list.setLayoutManager(new LinearLayoutManager(this));
        jinbi_list.setAdapter(mPresenter.getJinBiListAdapter());
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.title_back) {
            finish();
        } else if (id == R.id.jinbi_tixianjilu) {
            TiXianJiLuActivity.startActivity(getActivity());
        } else if (id == R.id.jinbi_tixian) {
            TiXianActivity.startActivity(getActivity(),jinbi_yue.getText().toString().trim());
        } else if (id == R.id.jinbi_jifenduihuanjilu) {
//            JiFenDuiHuanJiLuActivity.startActivity(getActivity());
        }
    }

    @Override
    public XRecyclerView getListView() {
        return jinbi_list;
    }

    @Override
    public void showJinBiNum(String coins) {
        jinbi_yue.setText(coins+"");
    }

    @Override
    public void onEvent(MessageEvent messageEvent) {
        super.onEvent(messageEvent);
        if (messageEvent.getCode()== EventbusCode.CODE_TIXIAN_OK){
            jinbi_list.refresh();
        }
    }
}
